import { DisposeView } from "../../../mvc/core/DisposeView";
import { LadderBattlefieldTopListVo } from "./vo/LadderBattlefieldTopListVo";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { LadderBattlefieldUtil } from "./LadderBattlefieldUtil";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { EDressPos } from "../../../../Message/Public/EDressPos";
import { SLadderToplists } from "../../../../Message/Public/SLadderToplists";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ResFileConst } from "../../resource/ResFileConst";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { LadderBattlefieldRankingRenderer } from "./renderer/LadderBattlefieldRankingRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiledBitmap } from "../../../../com/mui/controls/GTextFiledBitmap";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { LadderBattlefieldPairBtn } from "../../../../ResFileConst/LadderBattlefieldPairBtn";
type int = number;
//class LadderBattlefieldRankingView
    
    export  class LadderBattlefieldRankingView extends DisposeView
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */getToplist(arg1: int, arg2: Boolean=false): void
        {
            var loc1=new LadderBattlefieldTopListVo();
            loc1.page = arg1;
            loc1.pageSize = 8;
            loc1.orderObjType = Cache.instance.ladderBattlefield.multiTabBarSelectIndex;
            loc1.onlyMyServer = false;
            loc1.showMyPos = arg2;
            if (arg2 && (Cache.instance.ladderBattlefield.ladderCareer == 0 || !(loc1.orderObjType == Cache.instance.ladderBattlefield.ladderCareer))) 
            {
                MsgManager.showRollTipsMsg(Language.getString(28834));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldGetToplist, loc1));
            return;
        }

        /* internal  */onClickRefreshBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            LadderBattlefieldUtil.cleanSkillObj();
            return;
        }

        /* internal  */onInputTxtChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (int(this._inputTxt.text) > this._pageSelecter.maxPage) 
            {
                this._inputTxt.text = this._pageSelecter.maxPage.toString();
            }
            return;
        }

        /* internal  */onListPageChange(arg1: Object /* flash.events.Event */=null): void
        {
            this.getToplist(this._pageSelecter.currentPage);
            return;
        }

        /* internal  */onClickApplyBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.ladderBattlefield;
            if (ItemsUtil.hasItemByPos(EDressPos._EDressPosWeapon)) 
            {
                if (loc1.ladderCareer == -1) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28802));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldSignUp, loc1.isSignUp));
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(28829));
            }
            return;
        }

        /* internal  */onLinkReturnTxtHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            this.getToplist(int(this._inputTxt.text));
            return;
        }

        /* internal  */onLinkMyPosTxtHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            this.getToplist(1, true);
            return;
        }

        public set toplist(arg1: SLadderToplists)
        {
            this._pageSelecter.maxPage = arg1.pageNum;
            this._pageSelecter.currentPage = arg1.page;
            this._list.dataProvider = new DataProvider(arg1.toplists);
            this._list.drawNow();
            return;
        }

        public setSignUpBtnStyle(): void
        {
            this._applyBtn.styleName = Cache.instance.ladderBattlefield.isSignUp ? ResFileConst.LadderBattlefieldCancelBtn : LadderBattlefieldPairBtn;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            var loc1=Cache.instance.ladderBattlefield;
            if (loc1.multiTabBarSelectIndex >= 0 && loc1.ladderCareer <= 0) 
            {
                this.getToplist(1);
            }
            this.setSignUpBtnStyle();
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 425, 330, this));
            pushUIToDisposeVec(ObjCreate.createBg(-1, -3, 430, 32, this, ImagesConst.RbListHeader));
            this._ranking = ObjCreate.createGTextFiledBitmap("", 20, 20, 220, 20, this);
            if (!this._list) 
            {
                this._list = ObjCreate.createTileList(0, 30, 425, 245);
                this._list.scrollPolicy = ScrollPolicy.AUTO;
                this._list.columnWidth = 425;
                this._list.rowHeight = 30;
                this._list.setStyle("cellRenderer", LadderBattlefieldRankingRenderer);
            }
            this.addChild(this._list);
            this._pageSelecter = ObjCreate.createPageSelecter(80, 345, this);
            this._pageSelecter.mode = PageSelecter.CompleteMode;
            this._pageSelecter.configEventListener(flash.events.Event.CHANGE, this.onListPageChange);
            this._inputTxt = ObjCreate.createGTextInput(210, 345, 63, 20, this);
            this._inputTxt.restrict = "0-9";
            this._inputTxt.configEventListener(flash.events.Event.CHANGE, this.onInputTxtChangeHandler);
            this._applyBtn = ObjCreate.createGLoadedButton(ResFileConst.LadderBattlefieldPairBtn, 163, 280, 97, 42, this);
            this._applyBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onClickApplyBtnHandler);
            var loc1=ObjCreate.createGTextField("", 280, 345, 30, 20, this);
            loc1.htmlText = HTMLUtil.addLink(Language.getString(28827), GlobalStyle.color5);
            loc1.configEventListener(flash.events.TextEvent.LINK, this.onLinkReturnTxtHandler);
            pushUIToDisposeVec(loc1);
            var loc2=ObjCreate.createGTextField("", 320, 345, 60, 20, this);
            loc2.htmlText = HTMLUtil.addLink(Language.getString(28821), GlobalStyle.color5);
            loc2.configEventListener(flash.events.TextEvent.LINK, this.onLinkMyPosTxtHandler);
            pushUIToDisposeVec(loc2);
            var loc3=GlobalStyle.setTextFormatAlign(GlobalStyle._textFormat2, flash.text.TextFormatAlign.CENTER);
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28817), 0, 5, 60, 20, this, loc3));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28818), 60, 5, 180, 20, this, loc3));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28819), 240, 5, 40, 20, this, loc3));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28835), 280, 5, 70, 20, this, loc3));
            pushUIToDisposeVec(ObjCreate.createGTextFiledBitmap(Language.getString(28820), 350, 5, 70, 20, this, loc3));
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._ranking.dispose(arg1);
            this._applyBtn.dispose(arg1);
            this._inputTxt.dispose(arg1);
            this._pageSelecter.dispose(arg1);
            this._ranking = null;
            this._applyBtn = null;
            this._inputTxt = null;
            this._pageSelecter = null;
            return;
        }

        /* internal */ /* var */_applyBtn: GLoadedButton;

        /* internal */ /* var */_ranking: GTextFiledBitmap;

        /* internal */ /* var */_inputTxt: GTextInput;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelecter: PageSelecter;
    }
